package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.Statistics;
import cn.xscrum.demo.service.IStatisticsService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 18年数据总和Controller
 * 
 * @author xscrum
 * @date 2020-11-18
 */
@Controller
@RequestMapping("/demo/statistics")
public class StatisticsController extends BaseController
{
    private String prefix = "demo/statistics";

    @Autowired
    private IStatisticsService statisticsService;

    @RequiresPermissions("demo:statistics:view")
    @GetMapping()
    public String statistics()
    {
        return prefix + "/statistics";
    }

    /**
	 * 查询18年数据总和列表
     */
    @RequiresPermissions("demo:statistics:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Statistics statistics)
    {
        startPage();
        List<Statistics> list = statisticsService.selectStatisticsList(statistics);
        return getDataTable(list);
    }

    /**
	 * 导出18年数据总和列表
     */
    @RequiresPermissions("demo:statistics:export")
    @Log(title = "18年数据总和", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Statistics statistics)
    {
        List<Statistics> list = statisticsService.selectStatisticsList(statistics);
        ExcelUtil<Statistics> util = new ExcelUtil<Statistics>(Statistics.class);
        return util.exportExcel(list, "statistics");
    }

    /**
	 * 新增18年数据总和
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存18年数据总和
     */
    @RequiresPermissions("demo:statistics:add")
    @Log(title = "18年数据总和", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Statistics statistics)
    {
        return toAjax(statisticsService.insertStatistics(statistics));
    }

    /**
	 * 修改18年数据总和
     */
    @GetMapping("/edit/{year}")
    public String edit(@PathVariable("year") String year, ModelMap mmap)
    {
        Statistics statistics = statisticsService.selectStatisticsById(year);
        mmap.put("statistics", statistics);
        return prefix + "/edit";
    }

    /**
	 * 修改保存18年数据总和
     */
    @RequiresPermissions("demo:statistics:edit")
    @Log(title = "18年数据总和", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Statistics statistics)
    {
        return toAjax(statisticsService.updateStatistics(statistics));
    }

    /**
	 * 删除18年数据总和
     */
    @RequiresPermissions("demo:statistics:remove")
    @Log(title = "18年数据总和", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statisticsService.deleteStatisticsByIds(ids));
    }
}
